热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

angolajs|准则

angolajs|准则哎哎哎:#t0]https://www

angolajs |准则

哎哎哎:# t0]https://www . geeksforgeeks . org/angolajs-guidelines/

指令是文档对象模型中的标记。指令可以与任何控制器或 HTML 标记一起使用,这些标记将告诉编译器预期的确切操作或行为。存在一些预定义的指令,但是如果开发人员需要,他可以创建新的指令(自定义指令)。

下表列出了重要的内置 AngularJS 指令。

| 指令 | 描述 |
| ng 应用程序 | AngularJS 应用程序的开始。 |
| k-init | 用于初始化变量 |
| ng 模型 | ng-model 用于绑定到 HTML 控件 |
| ng-控制器 | 将控制器附着到视图 |
| 我的天啊 | 将该值与 HTML 元素绑定 |
| ng 重复 | 对指定集合中的每个项目重复一次 HTML 模板。 |
| ng 显示 | 显示或隐藏关联的 HTML 元素 |
| ng-只读 | 将 HTML 元素设为只读 |
| ng-禁用 | 用于动态禁用或启用按钮 |
| ng-if | 移除或重新创建 HTML 元素 |
| ng 点击 | 点击自定义步骤 |


  1. ng-app: The ng-app Directive in AngularJS is used to define the root element of an AngularJS application. This directive automatically initializes the AngularJS application on page load. It can be used to load various modules in AngularJS Application.
    Example: This example uses ng-app Directive to define a default AngularJS application.

    ```ts
     

     
        AngularJS ng-app Directive 

     
         
     

     

    ng-app directive

     
     
            

    {{ name }} is the portal for geeks.

     
        
     
     

     
    ```

    输出:


  2. ng-init:
    The ng-init directive is used to initialize an AngularJS Application data. It defines the initial value for an AngularJS application and assigns values to the variables.
    The ng-init directive defines initial values and variables for an AngularJS application.
    Example: In this example, we initialize an array of string.

    ts
     
         
     
        ng-cOntroller="myController"> 
        

    Input Box-

     
        
     
            
     
                Name- 
                                ng-model="name"> 
                
     {{ name }} 
    Checkbox- 
                                ng-model="check"> 
                
     {{ check }} 
    Radiobox- 
                                ng-model="choice"> 
                
     {{ choice }} 
    Number- 
                                ng-model="num"> 
                
     {{ num }} 
    Email- 
                                ng-model="mail"> 
                
     {{ mail }} 
    Url- 
                                ng-model="url"> 
                
     {{ url }} 
     
            
     
            
     
                Date: 
                 
                
     Todays date:{{ date1+1 }}
    Datetime-local- 
                 
                
     {{ date2+1 }} 
    Time- 
                 
                
     {{ time1+1 }} 
    Month- 
                 
                
     {{ mon+1 }} 
    Week- 
                 
                
     {{ we+1 }} 
     
            
     
        
     
     
     
     

    输出:


    1. ng-controller:
      The ng-controller Directive in AngularJS is used to add controller to the application. It can be used to add methods, functions and variables that can be called on some event like click, etc to perform certain action.
      Example:

      ```ts
       
       

       
          ng-controller Directive 

       
           
       

       

      GeeksforGeeks 
          

      ng-controller Directive


       
       
              Name:  
              

       

      You entered: {{name}} 
          

       

       
              var app = angular.module('app', []); 
              app.controller('geek', function ($scope) { 
                  $scope.name = "geeksforgeeks"; 
              }); 
           
       

       
      ```

      输出:


    2. ng-bind:
      The ng-bind directive in AngularJS is used to bind/replace the text content of any particular HTML element with the value that is entered in the given expression. The value of specified HTML content updates whenever the value of the expression changes in ng-bind directive.

      ```ts
       
       

       
          ng-checked Directive 

       
           
       

       

      GeeksforGeeks 
          

      ng-bind Directive

               
       
              num1:  
              

       

      num2:  
              

       

      Product:  
          

       

       
              var app = angular.module("gfg", []); 
              app.controller('app', ['$scope', function ($app) { 
                  $app.num1 = 1; 
                  $app.num2 = 1; 
                  $app.product = function () { 
                      $app.result = ($app.num1 * $app.num2); 
                  } 
              }]); 
           
       

       
      ```


    3. ng-repeat:
      Angular-JS ng-repeat directive is a handy tool to repeat a set of HTML code for a number of times or once per item in a collection of items. ng-repeat is mostly used on arrays and objects.
      ng-repeat is similar to a loop that we have in C, C++ or other languages but technically it instantiates a template(normally a set of HTML structures) for each element in a collection that we are accessing. Angular maintains a $index variable as a key to the element which is currently being accessed and the user can also access this variable.

      示例:


      1. Create an app.js file for the app.

        ```ts
        var app = angular.module('myApp',[]); 

        app.controller('MainCtrl', function($scope){ 
            $scope.names = ['Adam','Steve','George','James','Armin']; 
            console.log($scope.names); 
        }); 
        ```

        第 1 行- 创建了一个名为“myApp”的应用模块,没有依赖关系。
        3 号线- 主控制器供我们应用。
        第 4 行- 字符串“名称”数组。


      2. Create index.html page

        ts
         
         
         
             
             
             
             
         
         
            

        Here is the name list

         
            
           
                  
        •  
                      {{name}} 
                  
        •  
              
         
         

        第 5 行- 包含所有依赖项,如 jquery、angular-js 和 app.js 文件
        第 12 行- 使用 ng-repeat 指令一次从 names 数组中获取一个名称并显示。
        输出:




    4. ng-show:
      The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements.
      Example 1: This example uses ng-show Directive to display the HTML element after checked the checkbox.

      ```ts
       
       

       
          ng-show Directive 

       
           
       

       
          
       

      GeeksforGeeks 
              

      ng-show Directive

       

       

       
                  Show Paragraph 
               

       
                  Show this paragraph using ng-show 
              

       
          
       

       
              var myapp = angular.module("app", []); 
              myapp.controller("geek", function ($scope) { 
                  $scope.show = false; 
              }); 
           
       

                           
      ```

      输出:
      之前勾选了复选框:

      之后勾选了复选框:


      • ng-readonly:
        The ng-readonly Directive in AngularJS is used to specify the readonly attribute of an HTML element. The HTML element will be readonly only if the expression inside ng-readonly directive returns true.
        Example: This example uses ng-readonly Directive to enable readonly property.

      ```ts
       
       
          

       
              ng-readonly Directive 

       
               
           

       
              

      GeeksforGeeks 
              

      ng-readonly Directive

       
       
                  Check to make month readonly:  



       

      Input Month: 
              

       
           
                           
      ```

      输出:
      之前勾选了复选框:

      之后勾选了复选框:


      • ng-disabled:
        The ng-disabled Directive in AngularJS is used to enable or disable HTML elements. If the expression inside the ng-disabled attribute returns true then the form field will be disabled or vice versa. It is usually applied on form field (input, select, button, etc).
        Example 1: This example uses ng-disabled Directive to disable the button.

      ```ts
       
       

       
          ng-disabled Directive 

       
           
       

       

      GeeksforGeeks 

      ng-disabled Directive

       
       
               
                  Click to Disable 
               

       
                  Click to Enable 
               
          

       

       
              var app = angular.module("app", []); 
              app.controller('app', ['$scope', function ($app) { 
                  $app.geek = function (disable) { 
                      $app.disable = !disable; 
                  } 
              }]); 
           
       

       
      ```

      输出:
      点击按钮前:

      点击按钮后:


      • ng-if:
        The ng-if Directive in AngularJS is used to remove or recreate a portion of HTML element based on an expression. The ng-if is different from ng-hide because it completely removes the element in the DOM rather than just hiding the display of the element. If the expression inside it is false then the element is removed and if it is true then the element is added to the DOM.
        Example: This example changes the content after clicking the button.

      ```ts
       
       

       
          ng-hide Directive 

       
           
       

       

       
              GeeksforGeeks 
           

      ng-if Directive

       
       
              
       
                   

      Click to Sign in

       
              
       
       
                   
                      Sign out 
                   

       
                      GeeksforGeeks is the computer 
                      science portal for geeks. 
                  

       
              
       
          
       

       
              var app = angular.module("geek", []); 
              app.controller('app', ['$scope', function ($scope) { 
                  var vm = this; 
              }]); 
           
       

       
      ```

      输出:
      点击按钮前:


      点击按钮后:


      • ng-click:
        The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can popup alert when button is clicked.
        Example: This example uses ng-click Directive to display an alert message after clicking the element.

      ```ts
       
       

       
          ng-click Directive 

       
           
       

       

      GeeksforGeeks 
          

      ng-click Directive

       
       
               
                   
                      Click Here 
                   
               
          
       

       
              var app = angular.module("geek", []); 
              app.controller('app', ['$scope', function ($app) { 
                  $app.alert = function () { 
                      alert("This is an example of ng-click"); 
                  } 
              }]); 
           
       

       
      ```

      输出:
      点击按钮前:

      点击按钮后:



推荐阅读
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文详细介绍了PHP中与URL处理相关的三个函数:http_build_query、parse_str和查询字符串的解析。通过示例和语法说明,讲解了这些函数的使用方法和作用,帮助读者更好地理解和应用。 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
author-avatar
晓志1998_809
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有